<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>忘记密码</title>
    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/peizhi.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="css/all.css" />
</head>

<body>
    <style type="text/css">
    .container {
        padding-top: 15px;
    }

    .col-xs-3 {
        line-height: 35px;
        color: #999;
    }

    .col-xs-8,
    .col-xs-4 {
        margin-left: 0;
        padding-left: 0;
    }

    .row {
        padding-top: 8px;
        padding-bottom: 8px;
        border-bottom: 1px #EAEAEA solid;
    }

    .form-control {
        color: #333 !important;
        border: none;
    }

    .yanzhengma {
        line-height: 30px;
        padding: 0px 8px;
        border: 1px #EAEAEA solid;
        color: #000;
        z-index: 999;
        border-radius: 3px;
        position: absolute;
        right: 25px;
        top: 10px;
    }

    .form-control {
        background: none !important;
    }

    .form-control:focus {
        border-color: #66afe9;
        outline: 0;
        -webkit-box-shadow: inset 0px 0px 5px #FFFFFF
    }

    .go {
        background: #ffa328;
        font-weight: 600;
        color: #FFFFFF;
        text-align: center;
        font-size: 1.6rem;
        padding: 10px 0;
        margin-top: 20px;
        border-radius: 5px;
    }
    </style>
    <div class="alltop">
        <div class="backone2">
            <a href="JHdenglu.html"><span class="glyphicon glyphicon-menu-left"></span><b>返回</b></a>
        </div>
        <div class="refresh">
            <span class="glyphicon glyphicon-refresh"></span><b>刷新</b>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-xs-3 col-xs-offset-1">手机号</div>
            <div class="col-xs-8">
                <input type="text" class="form-control" name="" id="shoujihao" placeholder="请输入手机号" />
            </div>
        </div>
        <div class="row" style="position: relative;">
            <div class=""><input type="button" class="yanzhengma" value="验证码"> </div>
            <div class="col-xs-3 col-xs-offset-1">验证码</div>
            <div class="col-xs-4">
                <input type="text" class="form-control" name="" id="yanzhengma" value="" placeholder="请输入验证码" />
            </div>
        </div>
        <div class="row">
            <div class="col-xs-3 col-xs-offset-1">修改密码</div>
            <div class="col-xs-8">
                <input type="password" class="form-control" name="" id="password" value="" placeholder="请输入6-12位密码" />
            </div>
        </div>
        <div class="row">
            <div class="col-xs-3 col-xs-offset-1">确认密码</div>
            <div class="col-xs-8">
                <input type="password" class="form-control" name="" id="password2" value="" placeholder="请再次输入密码" />
            </div>
        </div>
        <div class="go">确认修改</div>
    </div>
    <script type="text/javascript" src="../lib/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/bootstrap.min.js"></script>
    <script type="text/javascript" src="../lib/vue.min.js"></script>
    <script type="text/javascript" src="../lib/common.js"></script>
    <script src="../lib/md5.js" type="text/javascript"></script>
    <script src="../lib/soha.js" type="text/javascript"></script>
    <script type="text/javascript">
    var b = new Base64(); //加密

    var phone;
    // 生成当前时间
    var myDate = new Date();
    var timedata = _dateFormat(myDate, 'yyyy-MM-dd');
    var code = "";

    function invokeSettime(obj){
                var countdown=60;
                settime(obj);
                function settime(obj) {
                    if (countdown == 0) {
                        $(obj).attr("disabled",false);
                        $(obj).val("获取验证码");
                        countdown = 60;
                        return;
                    } else {
                        $(obj).attr("disabled",true);
                        $(obj).val("(" + countdown + ") s 重新发送");
                        countdown--;
                    }
                    setTimeout(function() {
                                settime(obj) }
                            ,1000)
                }
            }

    
    $(".yanzhengma").click(function() {
        var shoujihao = $("#shoujihao").val();
        phone = shoujihao;
        if ( shoujihao == "" ) {
                    alert("请输入手机号！");
                    return ;
                }
        new invokeSettime(".yanzhengma");
        postJSON('/api/obtainaliyunsmsauthcode', {
            "phone": shoujihao,
            "atype": 0,
        }, function(result) {
            code = result.msg;

        }, function(result) {
            console.log("失败", result);
        });
    });
    $(".go").click(function() {
        var yanzhengma = $("#yanzhengma").val(); //验证码
        var password = $("#password").val(); //密码
        var password2 = $("#password2").val(); //重复密码
        var codemd5 = hex_md5(yanzhengma);
        if (code != codemd5) {
            alert("请填写正确的验证码！");
            return;
        }

        if (yanzhengma != "") {
            if (password == password2 && password != "") {
                var tel = $("#shoujihao").val();
                if (tel != phone) {
                    alert("请填写正确的手机号码！");
                    return;
                }
                var dcode = yanzhengma;
                var password = password;
                var fphone = $("#fphone").val();
                var fid = parseInt($("#fid").val());
                 postJSON('/api/forgetpwd', { 
                                       "phone": tel,
                                        "atype": 0,
        }, function (result) {
            
            
        

	                postJSON('/api/updatepwd', {
	                    "phone": tel,
	                    "newpwd": password ,
	                    "atype": 0,
	                }, function(result) {
	                    alert("修改成功！");
	                     window.location.href='JHdenglu.html';

	                }, function(result) {
	                	if (result.status == 403 ) {
	                		alert(result.msg)
	                	}
	                    console.log("失败", result);
	                });
	            }, function (result) {

        });


            } else {
                alert("密码输入不一致");
            }
        } else {
            alert("请输入验证码");
        }
    })
    </script>
</body>

</html>